﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Xml.Serialization;
using T4UtilityBelt.UxDesigns.Bindings;
using T4UtilityBelt.UxDesigns.Controls;
using T4UtilityBelt.UxDesigns.Screens2.Renders;
using T4UtilityBelt.UxDesigns.Specialized;
using T4UtilityBelt.Writers;

namespace T4UtilityBelt.UxDesigns.Screens2
{
    public class EntityListScreen : EntityScreen<EntityListScreen, IEntityListScreenRenderer>
    {
        public EntityListScreen()
        {
            StandardConstructor();
        }

        public EntityListScreen(string entityName)
            : base(entityName)
        {
            StandardConstructor();
        }

        public EntityListScreen(string entityName, string screenName)
            : base(entityName, screenName)
        {
            StandardConstructor();
        }

        private void StandardConstructor()
        {
            _listBox = new ListBoxControl();
            ActionBar.Controls.Add(new ActionButton() { Click = new Binding("EditCommand"), Text = "Edit", IconUri = "Save", ShouldSerialize = false });
        }

        private ListBoxControl _listBox;
        public ListBoxControl ListBox
        {
            get 
            { 
                return _listBox; 
            }
            set
            {
                Controls.Switch(_listBox, value);
                _listBox = value;
            }
        }

        #region FilterControls

        //private readonly ControlCollection _filterControls = new ControlCollection();
        //public ControlCollection FilterControls
        //{
        //    get { return _filterControls; }
        //}

        //public IEnumerable<Control> AllFilterControls()
        //{
        //    if (FilterControls.Count > 0)
        //    {
        //        foreach (var c in FilterControls)
        //        {
        //            yield return c;
        //        }
        //    }
        //    else
        //    {
        //        foreach (var p in Entity.Properties)
        //        {
        //            yield return Control.Create(p);
        //        }
        //    }
        //}

        #endregion FilterControls

        internal override void FixModel(T4UtilityBelt.DataDesigns.EntityModel model)
        {
            base.FixModel(model);

            if (Entity != null)
            {
                _listBox.FixModel(Entity);
            }
        }

    }
}